<#if authority.is(5,"9") >
<table width="100%" height="100px">
	<tr><td>
		<table width="100%" border=1 bgcolor="#ffffff">
			<tbody><tr><td><h4><span id="auth.user.tip" /></h4></td></tr></tbody>
			<tr><td>请选择需分配权限的用户<div id="div.authuser.user" /></td></tr>
			<tr><td><span id="authdyna.tip" /></td></tr>
		 	<tr><td><div id="div.authdyna.user"/></td></tr>
		 	<tr><td>请选择要分配的权限类型<div id="div.authkind.user"/></td></tr>
		 	<tr><td align="center"><input type="button" id="auth.save.user" name="auth.save.user" value="确定"></td></tr>
		 </table>
		 
		</td>
	    <td valign="top">
	    	该节点已拥有的权限<span><a href="#" id="auth.del.user" name="auth.del.user">删除</a></span> 
		 	<div id="div.authhave.user">
		</td>
 	</tr>
</table>
 

<script type="text/javascript">
var dataURL = '/data/sc.action';//取数据的url

//-------------填充用户-------- 
var allusers;
//var allusers_pageno = 1;
//if (allusers) { allusers_pageno = allusers.findCurrentPage(); }
var loadAllusersList = function(){
	dataURLParams = {"scid":"authuserinfos_2"}; 
	var columns = [{text:'序号',name:'id'},{text:'用户名',name:'username'},{text:'真实姓名',name:'realname'}];//要显示的字段
	if (!allusers){
		allusers = new MUI.List({
			instanceName: 'allusers',
	       	container:'div.authuser.user',
	       	showCheckBox:true,
			showCommand:false,
	       	id: 'authALLuserList',
	       	columns:columns,
	       	dataURL:dataURL,
	       	dataURLParams:dataURLParams,
	       	cbName: 'idsAlluser',
	       	saveCheck:true,
	       	commands:[]
	   	});//MUI.List
   	}
   	allusers.setDataURLParams(dataURLParams);
   	//allusers.findList(allusers_pageno);
   	allusers.findList(1,true);
}

//-------------填充扩展权限-------- 
var dynanode_user;
//var dynanode_user_pageno = 1;
//if (dynanode_user) { dynanode_user_pageno = dynanode_user.findCurrentPage(); }

var loadAuthDynaNodeUserList = function(){

	var columns = [{text:'扩展权限',name:'pcol'},{text:'扩展说明',name:'vcol'}];//要显示的字段
	var dataURLParams = {"scid":"authnodedyna", "authid":nodeinfo.id};
	if (!dynanode_user){
		dynanode_user = new MUI.List({
			instanceName: 'dynanode_user',
	       	container:'div.authdyna.user',
	       	showCheckBox:true,
			showCommand:false,
	       	id: "adynanode_userList",
	       	columns:columns,
	       	dataURL:dataURL,
	       	dataURLParams: dataURLParams,
	       	cbName: 'idsdynanode_user',
	       	saveCheck:true,
	       	commands:[]
	   	});//MUI.List
   	}
   	dynanode_user.setDataURLParams(dataURLParams);
   	//dynanode_user_pageno = 1;
   	//dynanode_user.findList(dynanode_user_pageno);
   	dynanode_user.findList(1,true);
}

//-------------填充权限类型 
var authkind_user;
//var authkind_user_pageno = 1;
//if (authkind_user) { authkind_user_pageno = authkind_user.findCurrentPage(); }

var loadAuthKind_userList = function(){
	var columns = [{text:'权限代号',name:'kind'},{text:'权限类型',name:'kindname'}];//要显示的字段
	var dataURLParams = {"scid":"authkindsetter","authid":nodeinfo.id,"pcolvalue":nodeinfo.pcolvalue};
	if (!authkind_user){
		authkind_user = new MUI.List({
			instanceName: 'authkind_user',
	       	container:'div.authkind.user',
	       	showCheckBox:true,
			showCommand:false,
	       	id: "authkind_userList",
	       	columns:columns,
	       	dataURL:dataURL,
	       	dataURLParams: dataURLParams,
	       	cbName: 'idsauthkind_user',
	       	saveCheck:true,
	       	commands:[]
	   	});//MUI.List
   	}
   	authkind_user.setDataURLParams(dataURLParams);
   	//authkind_user_pageno = 1;
   	//authkind_user.findList(authkind_user_pageno);
   	authkind_user.findList(1,true);
}


//填充该用户已拥有的权限
var authhave_user;
//var authhave_user_pageno = 1;
//if (authhave_user) { authhave_user_pageno = authhave_user.findCurrentPage(); }

var loadAuthhave_userList = function(){
	var columns="";
	var dataURLParams = "";
	if( 0==nodeinfo.kind ){
		columns = [{text:'序号',name:'id'},{text:'用户名',name:'username'},{text:'权限类型',name:'kindname'}];//要显示的字段
		dataURLParams = {"scid":"authuserinfos_1", "authid":nodeinfo.id};
	}else{  
		columns = [{text:'序号',name:'id'},{text:'扩展字段',name:'vcolvalue'},{text:'用户名',name:'username'},{text:'权限类型',name:'kindname'}];//要显示的字段
		dataURLParams = {"scid":"authuserinfos_dyna", "authid":nodeinfo.id};
	}
	if (!authhave_user){
		authhave_user = new MUI.List({
			instanceName: 'authhave_user',
	       	container:'div.authhave.user',
	       	showCheckBox:true,
			showCommand:false,
	       	id: "authhave_userList",
	       	columns:columns,
	       	dataURL:dataURL,
	       	dataURLParams: dataURLParams,
	       	cbName: 'idsauthhave_user',
	       	saveCheck:true,
	       	commands:[]
	   	});//MUI.List
   	}
   	authhave_user.setColumns(columns);
   	authhave_user.setDataURLParams(dataURLParams);
   	//authhave_user_pageno = 1;
   	//authhave_user.findList(authhave_user_pageno);
   	authhave_user.findList(1);
}



window.addEvent('domready', function() {
	new MUI.Require({
	  js: [MUI.path.plugins + 'mochaList/List.js'],
	  onload: function(){
		if(nodeinfo==null){
			MUI.notification('<font color=red>错误：</font> 未取得节点信息 ');
			return;
		}
		$('authdyna.tip').set('html','');
		loadAllusersList();
		if(1==nodeinfo.kind){
			$('authdyna.tip').set('html','请选择扩展权限');
			loadAuthDynaNodeUserList();
		}
		loadAuthKind_userList(); 
		loadAuthhave_userList();
	  } 
	 
	}); 
	 $('auth.user.tip').set('html','权限分配操作:<font color=red >'+nodeinfo.title +'</font>');
	
	$('auth.save.user').addEvent('click', function(e){
		if(!allusers || !authkind_user) return;
		var checkids_dynanode_user = "";
		var dataURLParams = ""; 
		var checkids_users = allusers.getcurCheckIds();
		var checkids_kinds_user = authkind_user.getcurCheckIds();
		//alert(checkids_kinds_user+"");
		checkids_users = checkids_users + "";
		checkids_kinds_user = checkids_kinds_user + "";
		if(null==checkids_users || ""==checkids_users) { alert('必须选择一项要添加的用户'); return; }
		if(null==checkids_kinds_user || ""==checkids_kinds_user) { alert('必须选择一项要添加的权限种类'); return; }
		if(1==nodeinfo.kind){
			if(!dynanode_user) return;
			checkids_dynanode_user = dynanode_user.getcurCheckIds();
			if(null==checkids_dynanode_user || ""==checkids_dynanode_user) { alert('必须选择一项要添加的扩展权限'); return; }
			checkids_dynanode_user = checkids_dynanode_user + "";
			dynanode_user.clearCheckIds();
		}
		if(nodeinfo.kind==0){
			dataURLParams = {"scid":"authuserinfos_3",  "checkids_users":checkids_users, 
			"checkids_kinds_user":checkids_kinds_user, "authid":nodeinfo.id};
		}else{
			dataURLParams = {"scid":"authuserinfos_5",  "checkids_users":checkids_users, 
			"checkids_kinds_user":checkids_kinds_user, "checkids_dynanode_user":checkids_dynanode_user, 
			"authid":nodeinfo.id};
		}
		allusers.clearCheckIds();
		authkind_user.clearCheckIds();
		try {
			var request = new Request.JSON({
			url: dataURL,
			onComplete: function(json,text) {
				if (json.error.errorcode==0){
    				MUI.notification('添加成功！');
    				loadAuthhave_userList();
    				//取消所有选中的勾选
    				allusers.cancelAll();
    				authkind_user.cancelAll();
    				if(1==nodeinfo.kind) dynanode_user.cancelAll();
    			}else{
    				MUI.notification('<font color=red>错误：</font>('+json.error.retstring+')');
    			}
			}
		}).get(dataURLParams);
		} catch (ex) {
			MUI.notification('<font color=red>错误：</font>('+json.error.retstring+')');
		}
	});
	
	$('auth.del.user').addEvent('click', function(e){
		if(!authhave_user) return;
		checkids_authhave_user = authhave_user.getcurCheckIds();
		if(null==checkids_authhave_user || ""==checkids_authhave_user) { alert('必须选择一项要删除的用户权限'); return; }
		checkids_authhave_user = checkids_authhave_user + "";
		authhave_user.clearCheckIds();
		
		var dataURLParams = {"scid":"authuserinfos_4", "authkind":nodeinfo.kind, "checkids_authhave_user":checkids_authhave_user};
		try {
			var request = new Request.JSON({
			url: dataURL,
			onComplete: function(json,text) {
				if (json.error.errorcode==0){
    				MUI.notification('删除成功！');
    				loadAuthhave_userList();
    				//取消所有选中的勾选
    				authhave_user.cancelAll();
    			}else{
    				MUI.notification('<font color=red>错误：</font>('+json.error.retstring+')');
    			}
			}
		}).get(dataURLParams);
		} catch (ex) {
			MUI.notification('<font color=red>错误：</font>('+json.error.retstring+')');
		}
	});
});
</script>
<#else>
您无权访问该页面！
</#if>